define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'litestoreshoporder/index',
                    // add_url: 'litestoreshoporder/add',
                    // edit_url: 'litestoreshoporder/edit',
                    // del_url: 'litestoreshoporder/del',
                    multi_url: 'litestoreshoporder/multi',
                    table: 'litestore_shoporder',
                }
            });

            var table = $("#table");
            //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                $("#PlayFeelTotal").html(data.PlayFeelTotal);
                $("#FeelTotal").html(data.FeelTotal);
                $("#RemainderTotal").html(data.RemainderTotal);
                $("#PreferentialTotal").html(data.RemainderTotal);
                //这里我们手动设置底部的值

            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'shoporder_id',
                sortName: 'shoporder_id',
                searchFormVisible: true,
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'order_no', title: __('Order_no')},
                        {field: 'order_status', title: __('order_status'), searchList: {"0":__('order_status 0'),"1":__('order_status 1')}, formatter: Table.api.formatter.status},
                        {field: 'play_price', title: __('Play_price')},
                        {field: 'preferential', title: __('preferential'),operate:false},
                        {field: 'play_time', title: __('Play_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'play_name', title: __('Play_name'), searchList: {"1":__('Play_name 1'),"2":__('Play_name 2'),"3":__('Play_name 3')}, formatter: Table.api.formatter.normal},
                        {field: 'total_price', title: __('Total_price'), operate:false},
                        {field: 'remainder', title: '支付余额', operate:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime, operate:false},
                        {field: 'shop.name', title: __('Shop.name')},
                        {field: 'playUser_id', title: '支付用户',operate:false},
                        // {field: 'playuser.username', title: '支付用户'},
                        {field: 'shopcategory.name', title: __('Shopcategory.name'),operate:false},
                        // {field: 'user.username', title: __('User.username')},
                        {field: 'note', title: __('Note'),operate:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});